const storage = new store({
	defaults: {
		server: '127.0.0.1',
		port: 23366,
		secure: true,
		lastInitTime: 0,
	}
});

function saveUserCredential(name, pwd) {
	storage.set('username', name);
	storage.set('password', pwd);
}

function hasUserCredential() {
	return storage.has('username');
}

function setServer(addr, port, secure) {
	storage.set('server', addr);
	storage.set('port', port);
	storage.set('secure', secure);
}

function getServer() {
	return {
		addr: storage.get('server'),
		port: storage.get('port'),
		secure: storage.get('secure')
	};
}

function getCredential() {
	return {
		username: storage.get('username'),
		password: storage.get('password')
	};
}

function setupSaving() {
	parcel.onClose = function () {
		storage.set('lastInitTime', Date.now());
	};
}

function getLastLoginTime() {
	return storage.get('lastInitTime');
}
